<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <p>{{ sentence }}</p>
        <button title="btn" @click="showSentence">开始</button>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js"></script>
    <script>
        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    sentence: '',
                    data: '欢迎来到泰句心的世界。'
                }
            },
            methods:{
                showSentence(){
                    this.sentence = this.data
                }
            },
            watch:{
                sentence:function(){
                    console.log(1)
                    let index = 0
                    setInterval(() => {
                        index += 1
                        console.log(index)
                        this.sentence = this.data.slice(0, index)
                    }, 1000)
                }
            }
        })
    </script>
</body>
</html>